class Create<%= migration_class_name %> < ActiveRecord::Migration<%= "[#{ActiveRecord::Migration.current_version}]" if Statesman::Utils.rails_5_or_higher? %>
  def change
    create_table :<%= table_name %> do |t|
      t.string :to_state, null: false
      t.text :metadata<%= ", default: #{metadata_default_value}" unless mysql? %>
      t.integer :sort_key, null: false
      t.integer :<%= parent_id %>, null: false
      t.boolean :most_recent<%= ", null: false" if database_supports_partial_indexes? %>

      # If you decide not to include an updated timestamp column in your transition
      # table, you'll need to configure the `updated_timestamp_column` setting in your
      # migration class.
      t.timestamps null: false
    end

    # Foreign keys are optional, but highly recommended
    add_foreign_key :<%= table_name %>, :<%= parent_table_name %>

    add_index(:<%= table_name %>,
              %i(<%= parent_id %> sort_key),
              unique: true,
              name: "<%= index_name :parent_sort %>")
    add_index(:<%= table_name %>,
              %i(<%= parent_id %> most_recent),
              unique: true,
              <%= 'where: "most_recent",' if database_supports_partial_indexes? %>
              name: "<%= index_name :parent_most_recent %>")
  end
end
